package wave.robot.second;

import java.util.HashMap;
import java.util.Map;

public class StringAttributeMapFn
{

    public Map<String, StringBuilder> apply(
            String string)
    {
        Map<String, StringBuilder> map =
                new HashMap<String, StringBuilder>();

        StringBuilder currentSb =
                null;

        for (String word : string
                .split(" "))
        {
            String lowWord =
                    word
                            .toLowerCase();

            if (lowWord
                    .startsWith("/"))
            {
                currentSb =
                        map
                                .get(lowWord);

                if (currentSb == null)
                {
                    currentSb =
                            new StringBuilder();

                    map
                            .put(
                                    lowWord,
                                    currentSb);
                }

                continue;
            }

            if (currentSb != null)
            {
                currentSb
                        .append(word
                                + " ");
            }
        }

        return map;
    }

}
